﻿@model FTBS.Models.Entities.Film

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";

}
<h2>Thêm Phim</h2>

@using (Html.BeginForm("Create", "Film", null, FormMethod.Post,
                              new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)
      
    <table class="table striped bordered hovered" style="margin: 0px 0px 0px 40px">
        <tr>
            <td style="padding: 0px 10px 0px 20px">
                <div id="txtFilmName" style="font-weight: bold">
                    @Html.LabelFor(model => model.Name, "Tên phim")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.Name)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Name)</p>
                </div>
            </td>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.Length, "Độ dài")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.Length)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Length)</p>
                </div>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.Nation, "Quốc gia")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.Nation)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Nation)</p>
                </div>
            </td>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.Director, "Đạo diễn phim")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.Director)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Director)</p>
                </div>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.AgeLimit, "Lứa tuổi")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.AgeLimit)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.AgeLimit)</p>

                </div>
            </td>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.Actor, "Các diễn viên tham gia")
                </div>
                <div class="input-control text">
                    @Html.EditorFor(model => model.Actor)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Actor)</p>
                </div>
                <div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.CategoryId, "Thể loại")
                </div>
                <div id="categoryCombobox">
                    @Html.Partial("CategoryComboboxPartial", Model)
                </div>
                <a href="#" onclick="ActiveCate()">Thêm Thể Loại</a>
            </td>
            <td style="padding: 0px 10px 0px 20px">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.FormatId, "Định dạng")
                </div>
                <div id="formatCombobox">
                    @Html.Partial("FormatComboboxPartial", Model)
                </div>
                <a href="#" onclick="ActiveFormat()">Thêm Định Dạng</a>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px 10px 0px 20px" colspan="2">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.Description, "Miêu tả phim")
                </div>
                <div class="input-control textarea">
                    @Html.TextAreaFor(model => model.Description)
                    <p style="color: red; font-size: 10pt">@Html.ValidationMessageFor(model => model.Description)</p>
                </div>
            </td>
        </tr>
        <tr>
            <td style="padding: 0px 10px 0px 20px" colspan="2">
                <div style="font-weight: bold">
                    @Html.LabelFor(model => model.ImageURL, "Hình ảnh")
                </div>
                <div class="input-control file info-state" data-role="input-control">
                    <input id="ImagePath" title="Upload a product image" type="file" name="file"/>
                    <input type="text" id="__input_file_wrapper__" readonly="" style="z-index: 1; cursor: default;">
                    <button class="btn-file" type="button" name="submit"></button>
                </div>
                </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input class="info" type="submit" value="Lưu" />
                <input class="info" type="reset" value="Xoá" />
            </td>
        </tr>

    </table>
    @Html.ActionLink("Quay lại", "Index")
}

<div id="categoryPartial" style="display: none">
    @Html.Partial("CategoryPartial", new FTBS.Models.Entities.Category())
</div>

<div id="formatPartial" style="display: none">
    @Html.Partial("FormatPartial", new FTBS.Models.Entities.Format())
</div>

<script>
    function ActiveCate() {
        //Get value of div with id="categoryPartial" -> set attribute display = normal to show CreateCategory form
        var categoryPartial = document.getElementById("categoryPartial");
        categoryPartial.setAttribute("style", "display:normal");

        var formatPartial = document.getElementById("formatPartial");
        formatPartial.setAttribute("style", "display:none");

        //Send data = null to clear object after create
        $.ajax({
            url: "/Film/CategoryPartial",
            type: "GET",
            data: { categoryModel: null },
            success: function (data) {
                $('#categoryPartial').html(data);
            },
            error: function (data) {
                alert("fail");
            }
        });
    }

    function ActiveFormat() {
        //Get value of div with id="formatPartial" -> set attribute display = normal to show FormatPartial form
        var formatPartial = document.getElementById("formatPartial");
        formatPartial.setAttribute("style", "display:normal");

        var categoryPartial = document.getElementById("categoryPartial");
        categoryPartial.setAttribute("style", "display:none");

        //Send data = null to clear object after create
        $.ajax({
            url: "/Film/FormatPartial",
            type: "GET",
            data: { formatModel: null },
            success: function (data) {
                $('#formatPartial').html(data);
            },
            error: function (data) {
                alert("fail");
            }
        });
    }
</script>



